home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kled.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  8.4 KB  |  330 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1998 J÷rg Habenicht (j.habenicht@europemail.com)
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public License
  15.     along with this library; see the file COPYING.LIB.  If not, write to
  16.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.     Boston, MA 02110-1301, USA.
  18. */
  19. /*************************************************************************
  20.  * $Id: kled.h 465272 2005-09-29 09:47:40Z mueller $
  21.  *************************************************************************/
  22.  
  23. #ifndef _KLED_H_
  24. #define _KLED_H_
  25.  
  26. #include <qwidget.h>
  27. #include <kdelibs_export.h>
  28.  
  29. class QColor;
  30. /**
  31.  * @short An LED widget.
  32.  *
  33.  * Displays a round  or rectangular light emitting diode.
  34.  *
  35.  * It is configurable to five colors, the two on/off states and three
  36.  * styles (or "looks");
  37.  *
  38.  * It may display itself in a performant flat view, a round view with
  39.  * light spot or a round view sunken in the screen.
  40.  *
  41.  * \image html kled.png "KDE LED Widget"
  42.  *
  43.  * @author Joerg Habenicht, Richard J. Moore (rich@kde.org) 1998, 1999
  44.  */
  45. class KDEUI_EXPORT KLed : public QWidget
  46. {
  47.     Q_OBJECT
  48.     Q_ENUMS( State Shape Look )
  49.     Q_PROPERTY( State state READ state WRITE setState )
  50.     Q_PROPERTY( Shape shape READ shape WRITE setShape )
  51.     Q_PROPERTY( Look look READ look WRITE setLook )
  52.     Q_PROPERTY( QColor color READ color WRITE setColor )
  53.     Q_PROPERTY( int darkFactor READ darkFactor WRITE setDarkFactor )
  54.  
  55. public:
  56.  
  57.   /**
  58.    * Status of the light is on/off.
  59.    * @short LED on/off.
  60.    */
  61.   enum State { Off, On };
  62.  
  63.   /**
  64.    * Shades of the lamp.
  65.    * @short LED shape
  66.    */
  67.   enum Shape { Rectangular, Circular };
  68.  
  69.   /**
  70.    * Displays a flat, round or sunken LED.
  71.    *
  72.    * Displaying the LED flat is less time and color consuming,
  73.    * but not so nice to see.
  74.    *
  75.    * The sunken LED itself is (certainly) smaller than the round LED
  76.    * because of the 3 shading circles and is
  77.    * most time consuming. Makes sense for LED > 15x15 pixels.
  78.    *
  79.    * \b Timings: \n
  80.    * ( AMD K5/133, Diamond Stealth 64 PCI Graphics, widgetsize 29x29 )
  81.    *  @li flat Approximately 0.7 msec per paint
  82.    *  @li round Approximately 2.9 msec per paint
  83.    *  @li sunken Approximately 3.3 msec per paint
  84.    *
  85.    * The widget will be updated on the next repaining event.
  86.    *
  87.    * @short LED look.
  88.    */
  89.   enum Look  { Flat, Raised, Sunken };
  90.  
  91.   /**
  92.    * Constructs a green, round LED widget which will initially
  93.    * be turned on.
  94.    */
  95.   KLed(QWidget *parent=0, const char *name=0);
  96.   /**
  97.    * Constructor with the ledcolor, the parent widget, and the name.
  98.    *
  99.    * The State will be defaulted On and the Look round.
  100.    *
  101.    * @param col Initial color of the LED.
  102.    * @param parent   Will be handed over to QWidget.
  103.    * @param name     Will be handed over to QWidget.
  104.    * @short Constructor
  105.    */
  106.   KLed(const QColor &col, QWidget *parent=0, const char *name=0);
  107.  
  108.   /**
  109.    * Constructor with the ledcolor, ledstate, ledlook,
  110.    * the parent widget, and the name.
  111.    *
  112.    * Differs from above only in the parameters, which configure all settings.
  113.    *
  114.    * @param col Initial color of the LED.
  115.    * @param state    Sets the State.
  116.    * @param look     Sets the Look.
  117.    * @param shape    Sets the Shape (rectangular or circular)
  118.    * @param parent   Will be handed over to QWidget.
  119.    * @param name     Will be handed over to QWidget.
  120.    * @short Constructor
  121.    */
  122.   KLed(const QColor& col, KLed::State state, KLed::Look look, KLed::Shape shape,
  123.        QWidget *parent=0, const char *name=0);
  124.  
  125.  
  126.   /**
  127.    * Destructor
  128.    * @short Destructor
  129.    */
  130.   ~KLed();
  131.  
  132.   /**
  133.    * Returns the current state of the widget (on/off).
  134.    *
  135.    * @see State
  136.    * @short Returns LED state.
  137.    */
  138.   State state() const;
  139.  
  140.   Shape shape() const;
  141.  
  142.   /**
  143.    * Returns the color of the widget
  144.    *
  145.    * @see Color
  146.    * @short Returns LED color.
  147.    */
  148.   QColor color() const;
  149.  
  150.   /**
  151.    * Returns the look of the widget.
  152.    *
  153.    * @see Look
  154.    * @short Returns LED look.
  155.    */
  156.   Look look() const;
  157.  
  158.   /**
  159.    * Returns the factor to darken the LED.
  160.    *
  161.    * @see setDarkFactor()
  162.    * @short Returns dark factor
  163.    */
  164.   int darkFactor() const;
  165.  
  166.   /**
  167.    * Sets the state of the widget to On or Off.
  168.    *
  169.    * The widget will be painted immediately.
  170.    * @see on() off() toggle() toggleState()
  171.    *
  172.    * @param state The LED state: on or off.
  173.    * @short Set LED state.
  174.    */
  175.   void setState( State state );
  176.  
  177.   /**
  178.    * Set the shape of the LED to @p s.
  179.    */
  180.   void setShape(Shape s);
  181.   /**
  182.    * Toggle the state of the LED from Off to On and vice versa.
  183.    *
  184.    * The widget will be repainted when returning to the main
  185.    * event loop.
  186.    * @short Toggles LED on->off / off->on.
  187.    * @deprecated, use #toggle() instead.
  188.    */
  189.   void toggleState() KDE_DEPRECATED;
  190.  
  191.   /**
  192.    * Set the color of the widget.
  193.    * The Color is shown with the KLed::On state.
  194.    * The KLed::Off state is shown with QColor.dark() method
  195.    *
  196.    * The widget calls the update() method, so it will
  197.    * be updated when entering the main event loop.
  198.    *
  199.    * @see Color
  200.    *
  201.    * @param color New color of the LED.
  202.    * @short Sets the LED color.
  203.    */
  204.   void setColor(const QColor& color);
  205.  
  206.   /**
  207.    * Sets the factor to darken the LED in OFF state.
  208.    * Same as QColor::dark().
  209.    * "darkfactor should be greater than 100, else the LED gets lighter
  210.    * in OFF state.
  211.    * Defaults to 300.
  212.    *
  213.    * @see QColor
  214.    *
  215.    * @param darkfactor sets the factor to darken the LED.
  216.    * @short sets the factor to darken the LED.
  217.    */
  218.   void setDarkFactor(int darkfactor);
  219.  
  220.   /**
  221.    * Sets the color of the widget.
  222.    * The Color is shown with the KLed::On state.
  223.    * darkcolor is explicidly used for the off state of the LED.
  224.    * Normally you don't have to use this method, the setColor(const QColor& color) is sufficient for the task.
  225.    *
  226.    * The widget calls the update() method, so it will
  227.    * be updated when entering the main event loop.
  228.    *
  229.    * @see Color setColor()
  230.    *
  231.    * @param color New color of the LED used for on state.
  232.    * @param darkcolor Dark color of the LED used for off state.
  233.    * @short Sets the light and dark LED color.
  234.    *
  235.   void setColor(const QColor& color, const QColor& darkcolor);
  236.   */
  237.  
  238.   /**
  239.    * Sets the look of the widget.
  240.    *
  241.    * The look may be flat, round or sunken.
  242.    * The widget calls the update() method, so it will
  243.    * be updated when entering the main event loop.
  244.    *
  245.    * @see Look
  246.    *
  247.    * @param look New look of the LED.
  248.    * @short Sets LED look.
  249.    */
  250.   void setLook( Look look );
  251.  
  252.   virtual QSize sizeHint() const;
  253.   virtual QSize minimumSizeHint() const;
  254.  
  255. public slots:
  256.  
  257.   /**
  258.    * Toggles the state of the led from Off to On or vice versa.
  259.    *
  260.    * The widget repaints itself immediately.
  261.    */
  262.   void toggle();
  263.  
  264.   /**
  265.    * Sets the state of the widget to On.
  266.    *
  267.    * The widget will be painted immediately.
  268.    * @see off() toggle() toggleState() setState()
  269.    */
  270.   void on();
  271.  
  272.   /**
  273.    * Sets the state of the widget to Off.
  274.    *
  275.    * The widget will be painted immediately.
  276.    * @see on() toggle() toggleState() setState()
  277.    */
  278.   void off();
  279.  
  280. protected:
  281.   /**
  282.    * Paints a circular, flat LED.
  283.    */
  284.   virtual void paintFlat();
  285.   /**
  286.    * Paints a circular, raised LED.
  287.    */
  288.   virtual void paintRound();
  289.   /**
  290.    * Paints a circular, sunken LED.
  291.    */
  292.   virtual void paintSunken();
  293.   /**
  294.    * Paints a rectangular, flat LED.
  295.    */
  296.   virtual void paintRect();
  297.   /**
  298.    * Paints a rectangular LED, either raised or
  299.    * sunken, depending on its argument.
  300.    */
  301.   virtual void paintRectFrame(bool raised);
  302.  
  303.   void paintEvent( QPaintEvent * );
  304.  
  305.   /**
  306.    * Compute LED width
  307.    */
  308.   int ensureRoundLed();
  309.  
  310.   /**
  311.    * Paint the cached antialiased pixmap corresponding to the state if any
  312.    * @return true if the pixmap was painted, false if it hasn't been created yet
  313.    */
  314.   bool paintCachedPixmap();
  315.  
  316. private:
  317.   State led_state;
  318.   QColor led_color;
  319.   Look  led_look;
  320.   Shape led_shape;
  321.  
  322. protected:
  323.   virtual void virtual_hook( int id, void* data );
  324. private:
  325.   class KLedPrivate;
  326.   KLedPrivate *d;
  327. };
  328.  
  329. #endif
  330.